package com.sky.consumer.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class SpringRabbitListener {
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue1"),
            exchange = @Exchange(name = "lucky.direct"),
            key = {"red","blue"}
    ))
    public void listenMsg1(String msg){
        log.info("消费者1接收到消息：{}",msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue2"),
            exchange = @Exchange(name = "lucky.direct"),
            key = {"red","yellow"}
    ))
    public void listenMsg2(String msg){
        log.info("消费者2接收到消息：{}",msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue1"),
            exchange = @Exchange(name = "lucky.topic",type = ExchangeTypes.TOPIC),
            key = {"china.#"}
    ))
    public void listenTopicMsg1(Map msg){
        log.info("消费者1接收到消息：{}",msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue2"),
            exchange = @Exchange(name = "lucky.topic",type = ExchangeTypes.TOPIC),
            key = {"japan.#"}
    ))
    public void listenTopicMsg2(Map msg){
        log.info("消费者2接收到消息：{}",msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue3"),
            exchange = @Exchange(name = "lucky.topic",type = ExchangeTypes.TOPIC),
            key = {"#.weather"}
    ))
    public void listenTopicMsg3(Map msg){
        log.info("消费者3接收到消息：{}",msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue4"),
            exchange = @Exchange(name = "lucky.topic",type = ExchangeTypes.TOPIC),
            key = {"#.news"}
    ))
    public void listenTopicMsg4(Map msg){
        log.info("消费者4接收到消息：{}",msg);
    }
}
